require "import"
import "android.speech.RecognizerIntent"
import "android.speech.SpeechRecognizer"
import "android.speech.RecognitionListener"
import "android.content.Intent"

if not service.getEditText() then
service.asyncSpeak("Sorry! Text Box Not Found!")
return false
end

local autoPunctuationByHemantSingal = " "

local recordIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
recordIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
recordIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "hi-IN")
local wordChangeTable = {

[""] = "", 
[""] = "", 
[""] = "", 


["कंट्री स्क्रीन रीडर"] = "कॉमेंट्री स्क्रीन रीडर",
["धन्यवाद"] = "ढणयवाद",
["उसे"] = "उस",
["जॉर्ज"] = "JAWS",
["एनवीडीया"] = "NVDA",
--["रूपी सिंबल"] = "₹",
--["रुपीस सिंबल"]= "₹",
["अल्पविराम"] = ", ",
["प्रश्न चीन"] = "? ",
["प्रश्न चिन्ह"] = "? ",
["प्रश्नवाचक"] = "? ",
["प्रश्न वाचक"] = "? ",
["विस्मय"] = "! ",
["विश्व में"] = "! ",
["बैंक सिंबल"] = "! ",
["न्यूलाइन"] = "\n",
["नई लाइन"] = "\n",
["न्यू लाइन"] = "\n",
["स्पेस"] = " ",
["थम्स अप"] = "👍",
["रेड हार्ट"] = "❤",
["रेड हॉट"] = "❤",
["फोल्डेड हैंड्स"] = "🙏",
["अति सुंदर"] = "👌",
["डॉट डॉट"] = "...",
["स्माइली फेस"] = "☺",

[""] = "", 
[""] = "", 
[""] = ""

}

local speechRecord = SpeechRecognizer.createSpeechRecognizer(service)
speechRecord.setRecognitionListener{
onResults = function(results)
local spokenText = results.getParcelableArrayList(SpeechRecognizer.RESULTS_RECOGNITION).get(0)
for k, v in pairs(wordChangeTable) do spokenText = spokenText:gsub(k, v) end
service.insertText(service.getEditText(), spokenText .. autoPunctuationByHemantSingal)
service.speak(spokenText)
speechRecord.destroy()
end,
onError = function()
speechRecord.destroy()
service.asyncSpeak("Sorry! I Did Not Understand Your Message!")
end
}
speechRecord.startListening(recordIntent)